﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OrganizedIN.UI.GroupContact
{
    public partial class CreateGroup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnregister_Click(object sender, EventArgs e)
        {
            OIDataContext dc = new OIDataContext();
            User_Organizer_Mapping uom = (from d in dc.User_Organizer_Mappings
                                          where d.username == Session["UserID"].ToString()
                                          select d).SingleOrDefault();

            Group_Master gm = new Group_Master();
            gm.Group_Name = txtgrpname.Text;
            gm.Group_Privacy = ddlprivacy.SelectedValue;
            gm.Group_CreateDate = DateTime.Now.ToString("D");
            string[] added = hdnSelected.Value.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in added)
            {
                Group_Contact_Mappin gcm = new Group_Contact_Mappin();
                gcm.username = s;
                gcm.AdminApproved = true;
                gcm.AdminRejected = false;
                gcm.RejectionCount = 0;
                gcm.AdminRejectionCount = 0;
                gcm.AdminRequestDate = DateTime.Now;
                gcm.Approved = false;
                gcm.Rejected = false;
                gm.Group_Contact_Mappins.Add(gcm);
            }
            uom.Group_Masters.Add(gm);
            dc.SubmitChanges();
            ClearGroupForm();
        }

        protected void btnCancel_Click1(object sender, EventArgs e)
        {
            ClearGroupForm();
        }

        private void ClearGroupForm()
        {
            txtgrpname.Text = "";
            ddlprivacy.SelectedIndex = 0;
            hdnSelected.Value = "";
        }
    }
}